package org.dtrd.modules.shop.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.dtrd.common.aspect.annotation.AutoLog;
import org.dtrd.modules.shop.entity.bean.PayRefundFlowDetail;
import org.dtrd.modules.shop.entity.bean.PayRefundFlowListInfo;
import org.dtrd.modules.shop.entity.bean.PayRefundFlowPageRequest;
import org.dtrd.modules.shop.service.IDtrdEntRdPayRefundFlowService;
import org.dtrd.common.api.vo.Result;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.RestController;
import org.dtrd.base.BaseController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import static org.dtrd.common.constant.CommonConstant.*;
import static org.dtrd.config.system.SystemState.ResponseState.*;

/**
 * <p>
 *  前端控制器
 * </p>
 * @author xiao
 * @since 2022-06-23
 */
@RestController
@RequestMapping("/payrefund")
@Api(tags = "收退款")
public class PayRefundFlowController extends BaseController {

    @Autowired
    private IDtrdEntRdPayRefundFlowService payRefundFlowService;

    @ApiOperation(value = "分页查询列表", response = PayRefundFlowListInfo.class)
    @PostMapping("/page")
    @AutoLog(value="查询列表", operateType = OPERATE_TYPE_QUERY)
    public Result<?> getPayRefundFlowList(@RequestBody PayRefundFlowPageRequest request){
        handlePageRequest(request);
        IPage<PayRefundFlowListInfo> page = payRefundFlowService.pagePayRefundFlow(request);
        return Result.OK(page);
    }

    @ApiOperation("新增或修改")
    @PostMapping("/save")
    @AutoLog(value="新增或修改", operateType = OPERATE_TYPE_SAVE_OR_UPDATE)
    public Result<?> saveOrUpdatePayRefundFlow(@RequestBody @Validated PayRefundFlowDetail dto){
//        if (StrUtil.isBlank(dto.getFlowCreateMonth())
//                || dto.getFlowType() == null
//                || dto.getFlowDoctorId() == null
//                || dto.getFlowChannel() == null
//                || dto.getFlowPatientId() == null
//                || StrUtil.isBlank(dto.getFlowPatientMobile())
//                || StrUtil.isBlank(dto.getFlowPatientName())) {
//            return error(STATE_PARAMS_ERROR);
//        }
        boolean result = payRefundFlowService.saveOrUpdatePayRefundFlow(dto);
        return result ? Result.OK() : error(STATE_OPERATION_FAILURE);
    }
}
